﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Pos.Model;

namespace Pos.DAL
{
    public class DishDAL
    {
        public int Add(DishInfo info) 
        {
            Database db = new Database();
            SqlParameter[] param =
            {
                db.MakeOutParam("@DishID",SqlDbType.Int,4),
                db.MakeInParam("@EnglishName",SqlDbType.VarChar,50,info.EnglishName),
                db.MakeInParam("@ChineseName",SqlDbType.VarChar,50,info.ChineseName),
                db.MakeInParam("@Price",SqlDbType.VarChar,50,info.Price),
            };
            try
            {
                db.ExecNonQuery("Pos_Dishes_Add", param);
                return DataHelper.GetInt(param[0].Value).Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }

        public DataTable GetAllByCategory(string CategoryID)
        {
            Database db = new Database();
            SqlParameter[] param =
            {
                db.MakeInParam("@CategoryID",SqlDbType.Int,4,CategoryID)
            };
            try
            {
                return db.GetDataSet("POS_Dishes_GetAllByCategory", param).Tables[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }
    }
}
